Workspace Object, Workspaces Collection Example

This example creates a new Microsoft Jet Workspace object and a new ODBCDirect Workspace object and appends them to the Workspaces collection. It then enumerates the Workspaces collections and the Properties collection of each Workspace object. See the methods and properties of the Workspace object or Workspaces collection for additional examples.

Sub WorkspaceX()

    Dim wrkNewJet As Workspace
    Dim wrkNewODBC As Workspace
    Dim wrkLoop As Workspace
    Dim prpLoop As Property

    ' Create a new Microsoft Jet workspace.
    Set wrkNewJet = CreateWorkspace("NewJetWorkspace", _
        "admin", "", dbUseJet)
    Workspaces.Append wrkNewJet

    ' Create a new ODBCDirect workspace.
    Set wrkNewODBC = CreateWorkspace("NewODBCWorkspace", _
        "admin", "", dbUseODBC)
    Workspaces.Append wrkNewODBC

    ' Enumerate the Workspaces collection.
    For Each wrkLoop In Workspaces
        With wrkLoop
            Debug.Print "Properties of " & .Name
            ' Enumerate the Properties collection of the new
            ' Workspace object.
            For Each prpLoop In .Properties
                On Error Resume Next
                If prpLoop <> "" Then Debug.Print "  " & _
                    prpLoop.Name & " = " & prpLoop
                On Error GoTo 0
            Next prpLoop
        End With
    Next wrkLoop

    wrkNewJet.Close
    wrkNewODBC.Close

End Sub